package com.xiaode.controller.app.teacher.gradeClass;

import com.jfinal.aop.Inject;
import com.jfinal.core.Controller;
import com.jfinal.core.Path;
import com.jfinal.ext.cors.EnableCORS;
import com.jfinal.kit.Ret;
import com.xiaode.common.model.Admin;
import com.xiaode.util.apidoc.annotation.Api;
import com.xiaode.util.apidoc.annotation.ApiOper;
import com.xiaode.util.apidoc.annotation.ApiPara;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Size;
import java.util.Date;

/**
 * 教师管理年级班级
 *
 */
@Path("/tGradeClass")
@Api("教师管理年级班级")
@EnableCORS
public class MyGradeClassController extends Controller {

    @Inject
    private MyGradeClassService service;

//    @ApiOper("查询教师拥有的年级班级")
//    public void findGradeClass()throws Exception{
//        Admin admin = getAttr("user");
//        Ret ret = service.findGradeClass(admin);
//        renderJson(ret);
//    }
    
    /**
     * 对应班级的分页
     */
    @ApiOper("查询某班学生信息")
    public void findStduentsPage(
	         @Size @ApiPara(value = "page",notes = "当前页")Integer page,
	         @Size @ApiPara(value = "limit",notes = "每页大小")Integer limit,
	         @NotBlank @ApiPara(value = "date",notes = "要查询的日期")Date date,
	         @Size @ApiPara(value = "clasId",notes = "班级id")Integer clasId)throws Exception{
        Admin admin = getAttr("user");
        Ret ret = service.findStduentsPage(admin, page, limit, date, clasId);
        renderJson(ret);
    }

    @ApiOper("教师确认学生缺席")
    public void studentAbsence(
            @NotBlank @ApiPara(value = "date",notes = "要查询的日期")Date date,
            @Size @ApiPara(value = "accountId",notes = "学生账号id")Integer accountId,
            @Size @ApiPara(value = "reason",notes = "缺席原因")String reason)throws Exception{
        Admin admin = getAttr("user");
        Ret ret = service.studentAbsence(admin, date, accountId,reason);
        renderJson(ret);
    }

    @ApiOper("教师取消学生缺席")
    public void cancelStudentAbsence(@NotBlank @ApiPara(value = "date",notes = "要查询的日期")Date date,
            @Size @ApiPara(value = "accountId",notes = "账号id")Integer accountId)throws Exception{
        Admin admin = getAttr("user");
        Ret ret = service.cancelStudentAbsence(admin, accountId,date);
        renderJson(ret);
    }


    /**
     * 获取班主任的班级
     */
    @ApiOper("查询某班学生信息")
    public void findStduents(
	         @Size @ApiPara(value = "page",notes = "当前页")Integer page,
	         @Size @ApiPara(value = "limit",notes = "每页大小")Integer limit,
	         @ApiPara(value = "date",notes = "要查询的日期")Date date)throws Exception{
        Admin admin = getAttr("user");
        Ret ret = service.findStduents(admin,page,limit,date);
        renderJson(ret);
    }

    @ApiOper("查询年级学生信息")
    public void  findGradeInfo()throws Exception{
        Admin admin = getAttr("user");
        Ret ret = service.findGradeInfo(admin);
        renderJson(ret);
    }

    @ApiOper("根据名称搜索")
    public void findStduentByName(@NotEmpty @ApiPara(value = "name",notes = "姓名")String name,
                                   @NotBlank @ApiPara(value = "date",notes = "日期")Date date)throws Exception{
        Admin admin = getAttr("user");
        Ret ret = service.findStduentByName(admin, name,date);
        renderJson(ret);
    }

    @ApiOper("教师提交缺勤记录")
    public void submitAbsence(@Size @ApiPara(value = "clasId",notes = "班级id")Integer clasId,
                                   @NotBlank @ApiPara(value = "date",notes = "缺勤日期")Date date)throws Exception{
        Admin admin = getAttr("user");
        Ret ret = service.submitClassAbsence(admin,clasId,date);
        renderJson(ret);
    }


    @ApiOper("卫生教师搜索学生")
    public void heathFindStudent(@Size @ApiPara(value = "name",notes = "姓名")String name,
                                 @NotBlank @ApiPara(value = "date",notes = "日期")Date date)throws Exception{
        Admin admin = getAttr("user");
        Ret ret = service.heathFindStudent(admin, name, date);
        renderJson(ret);
    }

    @ApiOper("查询全体缺勤记录")
    public void findAbsence(@NotBlank @ApiPara(value = "date",notes = "缺勤记录时间")Date date,
                            @Size @ApiPara(value = "page",notes = "当前页")Integer page,
                            @Size @ApiPara(value = "limit",notes = "每页大小")Integer limit)throws Exception{
        Admin admin = getAttr("user");
        Ret ret = service.findAbsence(admin,date,page,limit);
        renderJson(ret);
    }
}
